package com.uziot.bucket.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.uziot.bucket.dao.domain.PersionHouse;
import com.uziot.bucket.dao.mapper.PersionHouseMapper;
import com.uziot.bucket.service.PersonHouseDataService;
import com.uziot.bucket.service.PersonHouseService;
import com.uziot.galaxy.common.framework.component.AbstractExtractDataListCmp;
import com.uziot.galaxy.common.framework.component.AbstractExtractDataPageCmp;
import com.uziot.galaxy.common.framework.threadpool.ThreadPoolFactory;
import com.uziot.galaxy.dbtools.extract.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author shidt
 * @version V1.0
 * @className PersonHoustController
 * @date 2019-12-08 02:32:53
 * @description
 */
@RestController
public class PersonHouseController {
    @Autowired
    private PersionHouseMapper persionHouseMapper;
    @Autowired
    private PersonHouseService personHouseService;
    @Autowired
    private PersonHouseDataService personHouseDataService;

    @Resource
    private AbstractExtractDataPageCmp baseExtractDataCmp;
    @Resource
    private AbstractExtractDataListCmp baseExtractListCmp;

    @Resource
    private AbstractExtractDataListCmp baseExtractListCmpScott;
    @Resource
    private AbstractExtractDataPageCmp baseExtractPageCmpScott;

    @GetMapping(value = "/idcard/{idno}", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageInfo<PersionHouse> selectOneByCtfid(@RequestParam(defaultValue = "1") Integer pageNum,
                                                   @RequestParam(defaultValue = "10") Integer pageSize,
                                                   @PathVariable String idno) {
        PageHelper.startPage(pageNum, pageSize);
        List<PersionHouse> houses = persionHouseMapper.selectOneByCtfid(idno);
        return new PageInfo<>(houses);
    }


    @GetMapping(value = "/create")
    public String create() {
        personHouseService.createFile();
        return "OK";
    }

    @GetMapping(value = "/create2")
    public String create2() {
        personHouseDataService.createFile();
        return "OK";
    }

    @GetMapping(value = "/create3")
    public String create3() {
        Map<String, Object> cmpFile = baseExtractDataCmp.createFile();
        baseExtractDataCmp.createEndFile("end");
        return "OK";
    }

    @GetMapping(value = "/create4")
    public String create4() {
        Map<String, Object> cmpFile = baseExtractListCmp.createFile();
        baseExtractListCmp.createEndFile("end");
        return "OK";
    }

    @GetMapping(value = "/create5")
    public String create5() {
        Map<String, Object> cmpFile = baseExtractListCmpScott.createFile();
        baseExtractListCmp.createEndFile("end");
        return "OK";
    }

    @GetMapping(value = "/create6")
    public String create6() {
        Map<String, Object> cmpFile = baseExtractPageCmpScott.createFile();
        baseExtractPageCmpScott.createEndFile("end");
        return "OK";
    }


    @Resource
    private ExtractDataPageSqlCmpCustomizer extractDataPageSqlCmpCustomizer;
    @Resource
    private ExtractDataListSqlCmpCustomizer extractDataListSqlCmpCustomizer;


    @GetMapping(value = "/create7")
    public Map<String, Object> create7() {
        return extractDataPageSqlCmpCustomizer.createFile();
    }

    @GetMapping(value = "/create8")
    public Map<String, Object> create8() {
        return extractDataListSqlCmpCustomizer.createFile();
    }

    @Autowired
    private BatchExtractDataGroup batchExtractDataGroup;

    @GetMapping(value = "/create9")
    public String create9() {
        batchExtractDataGroup.batchCreateFile();
        return "ok";
    }

    @GetMapping(value = "/cmp/{id}")
    public String cmp(@PathVariable String id) {
        BatchExtractDataExecutor.getInstance().executeByCmpId(id);
        return "ok";
    }

    @GetMapping(value = "/cmpname/{cmpname}")
    public String cmpname(@PathVariable String cmpname) {
        BatchExtractDataExecutor.getInstance().executeByCmpName(cmpname);
        return "ok";
    }

    @GetMapping(value = "/batchname/{batchname}")
    public BatchExecuteResult batchname(@PathVariable String batchname) {
        return BatchExtractDataExecutor.getInstance().executeByBatchName(batchname);
    }
}
